package com.sgcc.fj.pmos.mobileapp.presenter;

import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.mobileapp.bean.AccountInfoBean;
import com.sgcc.fj.pmos.mobileapp.bean.CodeBean;
import com.sgcc.fj.pmos.mobileapp.contract.AccounNoInfoContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class AcctNoInfoPresenter extends BasePresenter<AccounNoInfoContract.View> implements AccounNoInfoContract.Presenter {


    @Override
    public void saveMater(Map<String, Object> params) {
        doMater(params);
    }

    public void doMater(Map<String, Object> params) {
        HttpRequestUtils.getInstance().request(params, HttpInterConst.SAVE_METER, new MvpNetCallback<AccountInfoBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
            }

            @Override
            public void onResponse(AccountInfoBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().saveMaterSuccess(response);
            }
        });
    }


    @Override
    public void getMaterList() {
        Map<String, Object> paramsnull = new HashMap<>();
        HttpRequestUtils.getInstance().request(paramsnull, HttpInterConst.QUERY_METERPOINTINFO, new MvpNetCallback<AccountInfoBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
            }

            @Override
            public void onResponse(AccountInfoBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().getMaterListSuccess(response);
            }
        });
    }

    @Override
    public void deletMeterPointInfo(String usePointId) {
        Map<String, Object> params = new HashMap<>();
        params.put("usePointId", usePointId);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.DELET_METERPOINTINFO, new MvpNetCallback<CodeBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
            }

            @Override
            public void onResponse(CodeBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().deletMeterPointInfoSuccess(response);
            }
        });
    }


}
